package com.kun.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kun.dao.SuppInfoDao;
import com.kun.entity.SuppInfo;
import com.kun.entity.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SuppInfoService {
    @Autowired
    private SuppInfoDao suppInfoDao;

    public SuppInfo findById(Integer suppId) {
        return suppInfoDao.selectByPrimaryKey(suppId);
    }

    public Map<String, Object> selectByPage(Integer pageNum, Integer pageSize, SuppInfo suppInfo) {
        //通过PageHelper对象设定分页参数
        PageHelper.startPage(pageNum, pageSize);
        //当前页面的数据
        List<SuppInfo> list = suppInfoDao.findAll(suppInfo);
        //创建PageInfo对象，并将当前页面数据传入，计算分页相关数据
        PageInfo<SuppInfo> pageInfo = new PageInfo<>(list);
        long total = pageInfo.getTotal();
        Map<String, Object> map = new HashMap<>();
        map.put("list", list);
        map.put("total", total);
        return map;
    }

    public int insertSupp(SuppInfo suppInfo) {
        return suppInfoDao.insert(suppInfo);
    }

    public int batchDelete(Integer[] userIds) {
        return suppInfoDao.batchDelete(userIds);
    }
    public int updateUser(SuppInfo suppInfo){
        return suppInfoDao.updateByPrimaryKeySelective(suppInfo);
    }

}